/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package simplemetrosystem.view.canvas.MouseHandlers;

import java.awt.event.MouseEvent;
import simplemetrosystem.control.Calculation.CalculManager;
import simplemetrosystem.model.Element.MetroStation;
import simplemetrosystem.view.MetroFrame;
import simplemetrosystem.view.canvas.CanvasModel;

/**
 *
 * @author Eric Qian
 */
public class CalculHandler extends BasicMouseHandler {

    /**
     * 
     * @param frame
     */
    public CalculHandler(MetroFrame frame) {
        super(frame);
        this.frame = frame;
        stab = true;
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        super.mouseClicked(e);
        CanvasModel model = CanvasModel.getInstance();

        int x = MouseTrans.X(e.getX());
        int y = MouseTrans.Y(e.getY());
        if (model.getCanvasElement(x, y) instanceof MetroStation) {
            if (stab) {
                //System.out.print("!!" + ((MetroStation) model.getCanvasElement(x, y)).getDisplayName());
                frame.getInfPane().getCalCulPane().setStationA((MetroStation) model.getCanvasElement(x, y));
                //CalculManager.getInstance().
                //        setStationA((MetroStation) model.getCanvasElement(x, y));
                stab = !stab;
            } else {
                //System.out.print("!!" + ((MetroStation) model.getCanvasElement(x, y)).getDisplayName());
                frame.getInfPane().getCalCulPane().setStationB((MetroStation) model.getCanvasElement(x, y));
                //CalculManager.getInstance().
                //        setStationB((MetroStation) model.getCanvasElement(x, y));
                stab = !stab;
            }
        }
    }
    private MetroFrame frame;
    private boolean stab;
}
